package com.yunche.yunchebusiness.mvp.presenter

import com.yunche.yunchebusiness.base.mvp.BasePresenter
import com.yunche.yunchebusiness.mvp.contract.TenantContract
import com.yunche.yunchebusiness.mvp.model.TenantModel
import com.yunche.yunchebusiness.network.exception.ErrorStatus
import com.yunche.yunchebusiness.network.exception.ExceptionHandle

/**
 * Create by Crcker on 2018/12/28 10:10
 * Email: Crcker@163.com
 */


class TenantPresenter : BasePresenter<TenantContract.View>(), TenantContract.Presenter {
    private val model by lazy {
        TenantModel()
    }

    override fun getTenantInfo() {
        checkViewAttached()
        mRootView?.showLoading()
        var disposable = model.getTenantInfo().subscribe({
            mRootView!!.apply {
                hideLoading()
                if (it.resultCode == ErrorStatus.SUCCESS) {
                    getTenantSuccess(it.datas!!)
                } else {
                    showError(it.message!!)
                }
            }
        }, {
            mRootView?.hideLoading()
            mRootView?.showError(ExceptionHandle.handleException(it))
        })
        addSubscription(disposable)
    }

}